<template>
  <div class="title">
    <div>
      <i class="el-icon-s-fold"></i> <span>企业级RBAC权限管理系统</span>
    </div>
    <div class="title-sousuo">
      <el-input style="padding: 0 14px">
        <i slot="prefix" class="el-icon-search"></i>
      </el-input>
    </div>
    <div class="title-users">
      欢迎您：
      <img
        :src="user.avatar"
        style="width: 40px; height: 40px; border-radius: 50%"
        alt=""
      />
      &nbsp;{{ user.username }}
    </div>
    <div>
      <el-button class="title-out" type="primary" @click="handlerOut"
        >退出系统</el-button
      >
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState(["user"]),
  },
  methods: {
    handlerOut() {
      this.$confirm("确定要退出吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //删除token
          localStorage.clear();
          this.$message({
            type: "success",
            message: "退出成功!",
            duration: 1000,
            onClose: () => {
              this.$router.push({
                path: "/login",
              });
            },
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消退出",
            duration: 1000,
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  display: flex;
  justify-content: space-between;
  height: 60px;
  background-color: #fff;
  z-index: 2;
  color: #517efb;
  font-size: 19px;
  font-weight: 600;
  line-height: 60px;
  width: calc(100vw - 240px);
  position: fixed;
  right: 0;
  top: 0;
  &-users {
    display: flex;
    align-items: center;
    color: #000;
    font-size: 12px;
    font-weight: 400;
    padding: 10px 0;
  }
  i {
    font-size: 18px;
    color: #5a5e66;
    padding: 0 16px;
  }
  &-out {
    font-size: 11px;
    padding: 7px 7px;
    margin-right: 10px;
  }
}
</style>